package com.kingchow.customdialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;


public class CenterDialog1 extends Dialog {

    private TextView mTvTitle;
    private Button mBtnAlbum, mBtnCamera;
    private String titleStr, albumStr, cameraStr;
    private OnClickButtonListener onClickButtonListener;

    /**
     * 构造方法
     *
     * @param context
     */
    public CenterDialog1(@NonNull Context context) {
        super(context, R.style.CustomDialogTheme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_centerdialog_1);
        //按空白处能取消动画
        setCanceledOnTouchOutside(true);
        //初始化界面控件
        initView();
        //初始化界面数据
        refreshView();
        //初始化界面控件事件
        initEvent();
    }

    /**
     * 初始化界面控件事件
     */
    private void initEvent() {
        //相册按钮点击事件
        mBtnAlbum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickButtonListener != null) {
                    onClickButtonListener.OnAlbumClick();
                }
            }
        });

        //相机按钮点击事件
        mBtnCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickButtonListener != null) {
                    onClickButtonListener.OnCameraClick();
                }
            }
        });
    }

    /**
     * 初始化界面数据
     */
    private void refreshView() {
        //初始化标题栏
        if (!TextUtils.isEmpty(titleStr)) {
            mTvTitle.setText(titleStr);
        } else {
            mTvTitle.setText(getContext().getResources().getString(R.string.choose_files));
        }
        mTvTitle.setVisibility(View.VISIBLE);

        //初始化相册按钮
        if (!TextUtils.isEmpty(albumStr)) {
            mBtnAlbum.setText(albumStr);
        } else {
            mBtnAlbum.setText(getContext().getResources().getString(R.string.openAlbum));
        }
        mBtnAlbum.setVisibility(View.VISIBLE);

        //初始化相机按钮
        if (!TextUtils.isEmpty(cameraStr)) {
            mBtnCamera.setText(cameraStr);
        } else {
            mBtnCamera.setText(getContext().getResources().getString(R.string.openCamera));
        }
        mBtnCamera.setVisibility(View.VISIBLE);

    }

    @Override
    public void show() {
        super.show();
        refreshView();
    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        mTvTitle = findViewById(R.id.CenterDialog1_title);
        mBtnAlbum = findViewById(R.id.CenterDialog1_fromAlbum);
        mBtnCamera = findViewById(R.id.CenterDialog1_fromCamera);
    }

    /**
     * 设置按钮点击事件的回调
     */
    public CenterDialog1 setOnClickButtonListener(OnClickButtonListener onClickButtonListener) {
        this.onClickButtonListener = onClickButtonListener;
        return this;
    }

    /**
     * 设置按钮点击事件的接口
     */
    public interface OnClickButtonListener {
        void OnAlbumClick();
        void OnCameraClick();
    }

    /**
     * 获取标题文本内容
     */
    public String getTitle() {
        return titleStr;
    }

    /**
     * 设置标题文本内容
     */
    public CenterDialog1 setTitle(String titleStr) {
        this.titleStr = titleStr;
        return this;
    }

    /**
     * 获取相册按钮文本内容
     */
    public String getAlbumButtoStr() {
        return albumStr;
    }

    /**
     * 设置相册按钮文本内容
     */
    public CenterDialog1 setAlbumButtonStr(String albumStr) {
        this.albumStr = albumStr;
        return this;
    }

    /**
     * 获取相机按钮文本内容
     */
    public String getCameraButtoStr() {
        return cameraStr;
    }

    /**
     * 设置相机按钮文本内容
     */
    public CenterDialog1 setCameraButtoStr(String cameraStr) {
        this.cameraStr = cameraStr;
        return this;
    }
}
